﻿using System;
using System.Web;
using System.Web.Mvc;
using System.IO;


namespace SisocanaBackEnd.Helpers
{

    public static class HtmlHelpers
    {
        public static String GoogleMap(this HtmlHelper helper, string idCoordX, string idCoordY, bool useGeolocation)
        {
            return String.Format("<a id='map_{0}_show' href=\"javascript:toggle('map_{0}','{0}','{1}','{2}');\">Show map</a>" +
            "<a id='map_{0}_hide' style='display: none;' href=\"javascript:toggle('map_{0}');\">Hide map</a>" +
            "<div id='map_{0}' style='display: none;'></div>", idCoordX, idCoordY, useGeolocation);
        }

        public static string VerPreview(this HtmlHelper helper, string id,string servPath)
        {
            Random r = new Random(DateTime.Now.Millisecond);
            int aleat1 = r.Next(10000);
            string ranString = aleat1.ToString();         

            
            string urlFisica = servPath + "/PreviewTenants/" + "ThumbBack" + id.Trim() + ".jpg";
            string url =  VirtualPathUtility.ToAbsolute("~/PreviewTenants/") + "ThumbBack" + id.Trim() + ".jpg";
            if (File.Exists(urlFisica)) { 
                url = url+"?chache=" + ranString;
            }else{
                //por default
                url = VirtualPathUtility.ToAbsolute("~/PreviewTenants/") + "ThumbBackDefault.jpg";                
            }
            
            
            string urlLupa = VirtualPathUtility.ToAbsolute("~/Content/Images/lupa.gif");

            string html = "<a href='' class='screenshot' rel='" +url+"'>"+ "<img width=13px heigth = 13px src='"+urlLupa+"' alt='Preview'/>"+"</a>";
            return html;
        }

        public static string ImagePopUpInit(this HtmlHelper helper)
        {
           
            string res = "<script src=\"" + VirtualPathUtility.ToAbsolute("~/Scripts/jquery-1.5.1.min.js") + "\"></script> \n";
            res += "<script src=\"" + VirtualPathUtility.ToAbsolute("~/Scripts/facebox.js") + "\"></script> \n";
            res += "<script src=\"" + VirtualPathUtility.ToAbsolute("~/Scripts/faceboxinit.js") + "\"></script> \n";
            res += "<link href=\"" + VirtualPathUtility.ToAbsolute("~/Content/facebox/facebox.css") + "\" rel=\"stylesheet\" type=\"text/css\"/> ";
            
            return res;

           
        }

        public static string Truncate(this HtmlHelper helper, string input, int length)
        {
            if ((input == null) || (input.Trim() == ""))
                return "No description.";
            if (input.Trim().Length <= length)
            {
                return input;
            }
            else
            {
                return input.Substring(0, length) + "...";
            }
        }

        public static string UrlFrontEnd(this HtmlHelper helper, string host)
        {
            return "http://" + host + "." + System.Configuration.ConfigurationManager.AppSettings["DominioFront"];
        }

        public static string LinkFrontEnd(this HtmlHelper helper, string host)
        {
            string url = UrlFrontEnd(helper, host);
            string res = "<a href=\"" + url + "\"  target=\"_blank\"  title=\"View Page\"  id=\"linkImg\" >" +
                "<img src=\"" + VirtualPathUtility.ToAbsolute("~/Content/Images/view.png") + "\" width=\"13\" height=\"13\" title=\"View Page\" /> </a> ";   
            return res;
        }

        public static string MakeImgLink(this HtmlHelper helper, string url,string title,string imgName)
        {
            string res = "<a href=\"" + url + "\"  title=\"View Page\"  id=\"linkImg\"  >" +
                "<img src=\"" + VirtualPathUtility.ToAbsolute("~/Content/Images/"+imgName) + "\" width=\"13\" height=\"13\" title=\""+title+"\" /> </a> "; return res;
        }

        public static string MakeImgLinkCustom(this HtmlHelper helper, string url, string title, string imgName,string att)
        {
            string res = "<a href=\"" + url + "\"  title=\"View Page\"  id=\"linkImg\" "+att+" >" +
                "<img src=\"" + VirtualPathUtility.ToAbsolute("~/Content/Images/" + imgName) + "\" width=\"13\" height=\"13\" title=\"" + title + "\" /> </a> "; return res;
        }

    }
}